<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增资产信息')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<style>
    span{
        z-index: 0;
    }
</style>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-assetDetail-add">
            <input name="manageDept" type="hidden" id="manageDept"/>
            <input name="deptId" type="hidden" id="deptId"/>
            <input name="companyId" type="hidden" id="companyId"/>
            <div class="form-group">
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>资产名称：</label>
                <div class="col-sm-8">
                    <input name="assetName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">卡片编号：</label>
                <div class="col-sm-8">
                    <input name="assetNo" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">资产编码：</label>
                <div class="col-sm-8">
                    <input name="assetCode" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>资产类别：</label>
                <div class="col-sm-8">
                    <select name="assetType" class="form-control select2-multiple" th:with="type=${@dict.getType('asset_type')}" required>
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属组织：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="companyName" onclick="selectCompanyTree()" id="companyName" type="text" placeholder="请选择组织" class="form-control">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">规格：</label>
                <div class="col-sm-8">
                    <input name="specifications" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">型号：</label>
                <div class="col-sm-8">
                    <input name="assetModel" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">单位：</label>
                <div class="col-sm-8">
                    <select name="assetUnit" class="form-control select2-multiple" th:with="type=${@dict.getType('unit_name')}">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">价格：</label>
                <div class="col-sm-8">
                    <input name="price" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>管理部门：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="manageDeptName" onclick="selectDeptTree()" id="manageDeptName" type="text" placeholder="请选择管理部门" class="form-control" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">管理人：</label>
                <div class="col-sm-8">
                    <select id="manageUser" name="manageUser" class="form-control select2-multiple">
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">投用时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="useDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">录入时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="putDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">消耗类型：</label>
                <div class="col-sm-8">
                    <select name="consumeType" class="form-control select2-multiple" th:with="type=${@dict.getType('consume_type')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>使用部门：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="deptName" onclick="selectDeptTreeUse()" id="deptName" type="text" placeholder="请选择使用部门" class="form-control" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">使用人：</label>
                <div class="col-sm-8">
                    <select id="useUser" name="useUser" class="form-control select2-multiple">
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">使用地点：</label>
                <div class="col-sm-8">
                    <input name="address" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">资产情况：</label>
                <div class="col-sm-8">
                    <select name="useStatus" class="form-control select2-multiple" th:with="type=${@dict.getType('use_status')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>数量：</label>
                <div class="col-sm-8">
                    <input name="amount" class="form-control" maxlength="8" type="number" min="1" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">
        var prefix = ctx + "asset/assetDetail"
        $("#form-assetDetail-add").validate({
            focusCleanup: true
        });
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-assetDetail-add').serialize());
            }
        }

        $("input[name='useDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='putDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        /*选择管理部门树*/
        function selectDeptTree() {
            var deptId = $.common.isEmpty($("#manageDept").val()) ? "100" : $("#manageDept").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#manageDept").val(body.find('#treeId').val());
                $("#manageDeptName").val(body.find('#treeName').val());
                layer.close(index);
            }
            $("#manageUser").empty();
            $.post(ctx +"system/user/getUserByDept",{deptId:$("#manageDept").val()},function (data) {
                $.each(data,function (index,p) {
                    $("#manageUser").append('<option value="'+p.userId+'">'+p.userName+'</option>');
                })
            });
        }
        //选择公司树
        function selectCompanyTree() {
            var deptId = $.common.isEmpty($("#companyId").val()) ? "100" : $("#companyId").val();
            var url = ctx + "system/dept/selectCompanyTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmitCompany
            };
            $.modal.openOptions(options);
        }
        function doSubmitCompany(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#companyId").val(body.find('#treeId').val());
                $("#companyName").val(body.find('#treeName').val());
                layer.close(index);
            }
        }
        /*选择使用部门树*/
        function selectDeptTreeUse() {
            var deptId = $.common.isEmpty($("#deptId").val()) ? "100" : $("#deptId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmitUse
            };
            $.modal.openOptions(options);
        }
        function doSubmitUse(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#deptId").val(body.find('#treeId').val());
                $("#deptName").val(body.find('#treeName').val());
                layer.close(index);
            }
            $("#useUser").empty();
            $.post(ctx +"system/user/getUserByDept",{deptId:$("#deptId").val()},function (data) {
                $.each(data,function (index,p) {
                    $("#useUser").append('<option value="'+p.userId+'">'+p.userName+'</option>');
                })
            });
        }
        $(function() {
            $.extend($.validator.defaults,{ignore:""});
            $('#manageUser').select2({
                placeholder:"管理人",
                allowClear: true
            });
            $('#useUser').select2({
                placeholder:"使用人",
                allowClear: true
            });
        })
    </script>
</body>
</html>